package com.zb.framework.wechatnews.utils;

import com.zb.framework.wechatnews.common.BizException;
import com.zb.framework.wechatnews.common.EnumsError;
import com.zb.framework.wechatnews.entity.BaseMessage;
import org.springframework.util.StringUtils;

/**
 * @Auther: 周作为
 * @Date: 2019/6/19 10:08
 * @Description:
 */
public class CheckParamsUtil {

    /**
     * 校验基本参数BaseMessage
     *
     * @param message
     */
    public static void checkBaseMessage(BaseMessage message) {
        //baseMessage不能为空
        if (null == message) {
            throw new BizException(EnumsError.BASEMESSAGE_ISEMPTY);
        }
        //消息类型不能为空
        if (StringUtils.isEmpty(message.getMsgtype())) {
            throw new BizException(EnumsError.MSGTYPE_ISEMPTY);
        }
        //应用id不能为空
        if (0 == message.getAgentid()) {
            throw new BizException(EnumsError.AGENTID_ISEMPTY);
        }

        //touser、toparty、totag不能同时为空
        if(StringUtils.isEmpty(message.getTouser())
                && StringUtils.isEmpty(message.getToparty())
                && StringUtils.isEmpty(message.getTotag())){
            throw new BizException(EnumsError.RECEIVE_ISEMPTY);
        }
    }
}
